package cn.framelife.rainbow.ui.wizard;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import cn.framelife.rainbow.ui.entity.ReverseProperty;
import cn.framelife.rainbow.ui.entity.WizardMessage;

/**
 * Reverse Wizard First Page
 * 主要填写Java类生成所需要的信息
 * @ClassName: ReverseFirstPage 
 * @author 潘广伟  p_3er@qq.com 
 * @date 2013年11月21日 下午3:42:46 
 *
 */
public class ReversePage extends WizardPage {
	private Button createPOJOCheckButton;
	private Button updateHibernateConfigCheckButton;
	private Button daoCheckButton;
	private Button generateBaseDaoButton;
	private Button serviceCheckButton;
	private Button actionCheckButton;
	private Button addUtilButton;
	private Button addJARsCheckButton;
	private Button pageCheckButton;
	private Button menuCheckButton;

	private ReverseProperty reverseProperty;
	
	/**
	 * Create the wizard.
	 */
	public ReversePage(WizardMessage message,ReverseProperty reverseProperty) {
		super(message.getPageTitle());
		setTitle(message.getPageTitle());
		setDescription(message.getPageDescription());
		this.reverseProperty = reverseProperty;
	}

	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite mainComposite = new Composite(parent, SWT.NULL);
		setControl(mainComposite);
			
		initUI(mainComposite);
		events();
	}
	
	/**
	 * 控件事件
	 *
	 * @Title: events 
	 * @param    
	 * @return void   
	 * @throws
	 */
	private void events(){	
		createPOJOCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				reverseProperty.setPOJO(createPOJOCheckButton.getSelection());
			}
		});
		
		updateHibernateConfigCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				reverseProperty.setUpdateConfigFile(updateHibernateConfigCheckButton.getSelection());
			}
		});
		
		daoCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				generateBaseDaoButton.setEnabled(daoCheckButton.getSelection());
				reverseProperty.setDAO(daoCheckButton.getSelection());
			}
		});
		
		serviceCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				reverseProperty.setService(serviceCheckButton.getSelection());
			}
		});
		
		actionCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				reverseProperty.setAction(actionCheckButton.getSelection());
			}
		});
		addJARsCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				reverseProperty.setJARs(addJARsCheckButton.getSelection());
			}
		});
		pageCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				menuCheckButton.setEnabled(pageCheckButton.getSelection());
				
				reverseProperty.setPage(pageCheckButton.getSelection());
			}
		});
		menuCheckButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				reverseProperty.setMenuAction(menuCheckButton.getSelection());
			}
		});
	}
	



	/**
	 * 初始化UI,由工具生成(没有重构)
	 * @param container
	 */
	private void initUI(Composite container) {
		container.setLayout(new GridLayout(4, false));
		
		Composite composite = new Composite(container, SWT.NONE);
		composite.setLayout(new GridLayout(1, false));
		GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite.widthHint = 584;
		composite.setLayoutData(gd_composite);
		
		createPOJOCheckButton = new Button(composite, SWT.CHECK);
		createPOJOCheckButton.setSelection(true);
		createPOJOCheckButton.setText("Create POJO with Hibernate mapping annotation for selected database tables");
		
		Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setLayout(new GridLayout(2, false));
		GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_composite_1.widthHint = 463;
		composite_1.setLayoutData(gd_composite_1);
		new Label(composite_1, SWT.NONE);
		
		updateHibernateConfigCheckButton = new Button(composite_1, SWT.CHECK);
		updateHibernateConfigCheckButton.setSelection(true);
		GridData gd_updateHibernateConfigCheckButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_updateHibernateConfigCheckButton.widthHint = 379;
		updateHibernateConfigCheckButton.setLayoutData(gd_updateHibernateConfigCheckButton);
		updateHibernateConfigCheckButton.setText("Update Spring Configuration with POJO location");
		
		Label sparator_2 = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_sparator_2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_sparator_2.widthHint = 589;
		sparator_2.setLayoutData(gd_sparator_2);
		
		Composite composite_2 = new Composite(container, SWT.NONE);
		composite_2.setLayout(new GridLayout(1, false));
		GridData gd_composite_2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_2.widthHint = 575;
		composite_2.setLayoutData(gd_composite_2);
		
		daoCheckButton = new Button(composite_2, SWT.CHECK);
		GridData gd_daoCheckButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_daoCheckButton.widthHint = 586;
		daoCheckButton.setLayoutData(gd_daoCheckButton);
		daoCheckButton.setText("Java Data Access Object (DAO)");
		
		Composite composite_3 = new Composite(composite_2, SWT.NONE);
		composite_3.setLayout(new GridLayout(2, false));
		GridData gd_composite_3 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_composite_3.widthHint = 564;
		composite_3.setLayoutData(gd_composite_3);
		new Label(composite_3, SWT.NONE);
		
		Composite composite_4 = new Composite(composite_3, SWT.NONE);
		composite_4.setLayout(new GridLayout(1, false));
		GridData gd_composite_4 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_composite_4.widthHint = 514;
		composite_4.setLayoutData(gd_composite_4);
		
		generateBaseDaoButton = new Button(composite_4, SWT.CHECK);
		generateBaseDaoButton.setEnabled(false);
		generateBaseDaoButton.setText("Generate Base DAO bean");
		generateBaseDaoButton.setSelection(true);
		
		Label sparator_3 = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_sparator_3 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_sparator_3.widthHint = 589;
		sparator_3.setLayoutData(gd_sparator_3);
		
		Composite composite_5 = new Composite(container, SWT.NONE);
		composite_5.setLayout(new GridLayout(1, false));
		GridData gd_composite_5 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_5.widthHint = 581;
		composite_5.setLayoutData(gd_composite_5);
		
		Composite composite_6 = new Composite(container, SWT.NONE);
		GridData gd_composite_6 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_6.widthHint = 581;
		composite_6.setLayoutData(gd_composite_6);
		
		serviceCheckButton = new Button(composite_6, SWT.CHECK);
		serviceCheckButton.setBounds(10, 10, 572, 16);
		serviceCheckButton.setText("Java Business Logic Object (Service)");
		
		Composite composite_9 = new Composite(container, SWT.NONE);
		GridData gd_composite_9 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_9.widthHint = 571;
		composite_9.setLayoutData(gd_composite_9);
		
		actionCheckButton = new Button(composite_9, SWT.CHECK);
		actionCheckButton.setBounds(10, 10, 431, 16);
		actionCheckButton.setText("Action Bean of Struts2");
		
		Composite composite_13 = new Composite(container, SWT.NONE);
		GridData gd_composite_13 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_13.widthHint = 571;
		composite_13.setLayoutData(gd_composite_13);
		
		addUtilButton = new Button(composite_13, SWT.CHECK);
		addUtilButton.setBounds(10, 10, 316, 16);
		addUtilButton.setText("Add JRainbow Util Class into the project");
		
		Composite composite_10 = new Composite(container, SWT.NONE);
		GridData gd_composite_10 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_10.widthHint = 575;
		composite_10.setLayoutData(gd_composite_10);
		
		addJARsCheckButton = new Button(composite_10, SWT.CHECK);
		addJARsCheckButton.setBounds(10, 10, 406, 16);
		addJARsCheckButton.setText("Add JARs of S2SH into the project");
		
		Composite composite_11 = new Composite(container, SWT.NONE);
		composite_11.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
		
		Button updateWebConfigCheckButton = new Button(composite_11, SWT.CHECK);
		updateWebConfigCheckButton.setText("Update Web Configuration with Spring config and Struts config ");
		updateWebConfigCheckButton.setBounds(10, 10, 487, 16);
		
		Composite composite_12 = new Composite(container, SWT.NONE);
		GridData gd_composite_12 = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
		gd_composite_12.heightHint = 78;
		composite_12.setLayoutData(gd_composite_12);
		
		pageCheckButton = new Button(composite_12, SWT.CHECK);
		pageCheckButton.setText("Add pages with Extjs for selected database tables");
		pageCheckButton.setBounds(10, 10, 443, 16);
		
		
		menuCheckButton = new Button(composite_12, SWT.CHECK);
		menuCheckButton.setBounds(40, 39, 528, 16);
		menuCheckButton.setText("Generate MenuData.json and MenuAction to Connect Page and Server ");
		menuCheckButton.setSelection(false);
		menuCheckButton.setEnabled(false);
		GridData gd_composite_14 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_composite_14.widthHint = 463;
		
	}
}
